<?xml version="1.0" encoding="UTF-8"?>
<!--
  Created by IntelliJ IDEA.
  User: arash
  Date: 11-11-17
  Time: 12:14 PM
-->
<!DOCTYPE html
        PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:p="http://primefaces.org/ui"
      xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:f="http://java.sun.com/jsf/core">

<ui:composition template="/WEB-INF/templates/prime.xhtml">
<ui:define name="head">
    <style type="text/css">
        .yui-dt {
            margin-top: 10px;
        }

        .yui-dt table {
            width: 100%;
        }

        .yui-ac {
            width: 200px;
            padding-bottom: 1em;
        }

        .label {
            width: 20%;
            padding: 4px;
        }

        .value {
            width: 80%;
            padding: 4px;
        }

        .grid {
            width: 100%;
        }
    </style>
</ui:define>


<ui:define name="content">
<h:form prependId="false">
    <p:dataTable id="instancesTable" lazy="false" paginator="false" var="instance"
                 value="#{panaceaController.instance}">
        <p:column>
            <f:facet name="header">
                <h:outputText value="Instance Name"/>
            </f:facet>
            <h:outputText value="#{instance.directory}" style="font-weight:bold"/>
        </p:column>
        <p:column>
            <f:facet name="header">
                <h:outputText value="Running"/>
            </f:facet>
            <h:outputText value="#{instance.running}"/>
        </p:column>
        <p:column>
            <f:facet name="header">
                Options
            </f:facet>
            <p:commandLink id="properties_link" async="true" update="propertiesTable"
                           oncomplete="propertiesDialog.show();">
                <h:graphicImage value="img/properties.png"/>
                <f:setPropertyActionListener value="#{instance}" target="#{panaceaController.instance}"/>
            </p:commandLink>
            <p:tooltip for="properties_link" value="Edit Properties" showEffect="fade" hideEffect="fade"/>

            <p:commandLink id="delete" async="true" onclick="confirmDelete.show();">
                <h:graphicImage value="img/edit-delete.png"/>
                <f:setPropertyActionListener value="#{instance}" target="#{panaceaController.instance}"/>
            </p:commandLink>
            <p:tooltip for="delete" value="Delete This Instance" showEffect="fade" hideEffect="fade"/>

            <p:commandLink id="mapping_link" async="true" onclick="mappingFileDialog.show();">
                <h:graphicImage value="img/mapping.png"/>
                <f:setPropertyActionListener value="#{instance}" target="#{panaceaController.instance}"/>
            </p:commandLink>
            <p:tooltip for="mapping_link" value="Upload Mapping File" showEffect="fade" hideEffect="fade"/>
            <p:commandLink id="publish_link" async="true" onclick="publishingFileDialog.show();">
                <h:graphicImage value="img/publishing.png"/>
                <f:setPropertyActionListener value="#{instance}" target="#{panaceaController.instance}"/>
            </p:commandLink>
            <p:tooltip for="publish_link" value="Upload Publishing file" showEffect="fade" hideEffect="fade"/>

            <p:commandLink id="template_link" async="true" onclick="templatesFileDialog.show();">
                <h:graphicImage value="img/templates.png"/>
                <f:setPropertyActionListener value="#{instance}" target="#{panaceaController.instance}"/>
            </p:commandLink>
            <p:tooltip for="template_link" value="Upload Template File" showEffect="fade" hideEffect="fade"/>

            <h:panelGroup rendered="#{!instance.running}">
                <p:commandLink id="start" async="true" action="#{panaceaController.start}"
                               update="messages instancesTable" ajax="false"
                               onclick="document.body.style.cursor='wait';">
                    <h:graphicImage value="img/start.png"/>
                    <f:setPropertyActionListener value="#{instance}" target="#{panaceaController.instance}"/>
                </p:commandLink>
                <p:tooltip for="start" value="Start Instance" showEffect="fade" hideEffect="fade"/>
            </h:panelGroup>

            <h:panelGroup rendered="#{instance.running}">
                <p:commandLink id="stop" async="true" action="#{panaceaController.stop}"
                               update="messages instancesTable" ajax="false"
                               onclick="document.body.style.cursor='wait';">
                    <h:graphicImage value="img/stop.png"/>
                    <f:setPropertyActionListener value="#{instance}" target="#{panaceaController.instance}"/>
                </p:commandLink>
                <p:tooltip for="stop" value="Stop Instance" showEffect="fade" hideEffect="fade"/>
            </h:panelGroup>
            <p:commandLink id="probe" async="true" action="#{panaceaController.probe}"
                           update="messages instancesTable">
                <h:graphicImage value="img/probe.png"/>
                <f:setPropertyActionListener value="#{instance}" target="#{panaceaController.instance}"/>
            </p:commandLink>
            <p:tooltip for="probe" value="Probe if instance is running" showEffect="fade" hideEffect="fade"/>

        </p:column>
    </p:dataTable>
    <p:panel id="main-panel" header="Files for #{panaceaController.instance.directory}">
        <p:accordionPanel>
            <p:tab title="Configuration Files">
                <p:commandLink value="Mapping File" async="true" oncomplete="fileDialog.show();" update="codePanel">
                    <f:setPropertyActionListener value="mapping.xml"
                                                 target="#{panaceaController.instance.currentFile}"/>
                </p:commandLink>
                <br/>
                <p:commandLink value="Publishing File" async="true" oncomplete="fileDialog.show();" update="codePanel">
                    <f:setPropertyActionListener value="publisher.xml"
                                                 target="#{panaceaController.instance.currentFile}"/>
                </p:commandLink>
                <br/>
                <p:commandLink value="Properties File" async="true" oncomplete="fileDialog.show();" update="codePanel">
                    <f:setPropertyActionListener value="panacea.properties"
                                                 target="#{panaceaController.instance.currentFile}"/>
                </p:commandLink>
            </p:tab>
            <p:tab title="Templates">
                <h:dataTable var="templateFile" value="#{panaceaController.instance.templateFiles}">
                    <h:column>
                        <p:commandLink value="#{templateFile}" async="true" oncomplete="fileDialog.show();"
                                       update="codePanel">
                            <f:setPropertyActionListener value="template_#{templateFile}"
                                                         target="#{panaceaController.instance.currentFile}"/>
                        </p:commandLink>
                        ........
                        <p:commandLink value="Delete" async="true" onclick="confirmTemplateDelete.show();"
                                       update="codePanel">
                            <f:setPropertyActionListener value="template_#{templateFile}"
                                                         target="#{panaceaController.instance.currentFile}"/>
                        </p:commandLink>
                    </h:column>
                </h:dataTable>
            </p:tab>
            <p:tab title="Logs">
                <h:dataTable var="logFile" value="#{panaceaController.instance.logFiles}">

                    <h:column>
                        <p:commandLink value="#{logFile}" async="true" oncomplete="fileDialog.show();"
                                       update="codePanel">
                            <f:setPropertyActionListener value="log_#{logFile}"
                                                         target="#{panaceaController.instance.currentFile}"/>
                        </p:commandLink>
                    </h:column>
                </h:dataTable>
            </p:tab>
        </p:accordionPanel>
    </p:panel>
</h:form>
<p:dialog widgetVar="fileDialog" id="fileDialogId" height="400" width="800" header="File Content"
          onShow="SyntaxHighlighter.all();">
                <pre class="brush: xml;">
                  <p:panel id="codePanel">
                      <h:outputText value="#{panaceaController.instance.currentFile}"/>
                  </p:panel>
                </pre>
</p:dialog>
<h:form>
    <p:confirmDialog message="Are you sure you want to delete this template?" severity="warn"
                     widgetVar="confirmTemplateDelete">
        <p:commandButton value="Yes" update="messages main-panel" action="#{panaceaController.deleteTemplateFile}"
                         oncomplete="confirmTemplateDelete.hide();"/>
        <p:commandButton value="No" oncomplete="confirmDialog.hide();"/>
    </p:confirmDialog>
</h:form>
<p:dialog id="properties" header="Properties" widgetVar="propertiesDialog" fixedCenter="true">
    <h:panelGroup id="propertiesTable">
        <p>
            Properties for #{panaceaController.instance.directory} :
        </p>
        <h:form>
            <h:panelGrid columns="2">
                <h:column><h:outputLabel for="ftp_url" value="Ftp URL:"/></h:column>
                <h:column><h:inputText id="ftp_url" value="#{panaceaController.instance.properties.ftpUrl}"/></h:column>
                <h:column><h:outputLabel for="ftp_username" value="FTP Username : "/></h:column>
                <h:column><h:inputText id="ftp_username" value="#{panaceaController.instance.properties.ftpUsername}"/></h:column>
                <h:column><h:outputLabel for="ftp_password" value="FTP Password : "/></h:column>
                <h:column><h:inputText id="ftp_password" value="#{panaceaController.instance.properties.ftpPassword}"/></h:column>
                <h:column><h:outputLabel for="newfile" value="Ftp fetch Cron Expression"/></h:column>
                <h:column><h:inputText id="newfile"
                                       value="#{panaceaController.instance.properties.fetchCron}"/></h:column>
                <h:column><h:outputLabel for="cron1" value="Publisher First Cron Expression"/></h:column>
                <h:column><h:inputText id="cron1"
                                       value="#{panaceaController.instance.properties.publisherCron1}"/></h:column>

                <h:column><h:outputLabel for="cron2" value="Publisher Second Cron Expression"/></h:column>
                <h:column><h:inputText id="cron2"
                                       value="#{panaceaController.instance.properties.publisherCron2}"/></h:column>
                <h:column><h:outputLabel for="cron3" value="Publisher Third Cron Expression"/></h:column>
                <h:column><h:inputText id="cron3"
                                       value="#{panaceaController.instance.properties.publisherCron3}"/></h:column>
                <h:column><h:outputLabel for="gsa_url" value="GSA Url : "/></h:column>
                <h:column><h:inputText id="gsa_url" value="#{panaceaController.instance.properties.gsaUrl}"/></h:column>
                <h:column><h:outputLabel for="gsa_datasource" value="GSA Data Source : "/></h:column>
                <h:column><h:inputText id="gsa_datasource"
                                       value="#{panaceaController.instance.properties.gsaDatasource}"/></h:column>
            </h:panelGrid>
            <h:commandButton action="#{panaceaController.saveProperties}" value="Save"/>
        </h:form>
    </h:panelGroup>
</p:dialog>
<h:form>
    <p:confirmDialog widgetVar="confirmDelete" message="Are you sure you want to delete this Panacea instance?"
                     severity="warn">
        <p:commandButton value="Yes" update="instancesTable messages" oncomplete="confirmDelete.hide()"
                         action="#{panaceaController.delete}" />
        <p:commandButton value="No" onclick="confirmDelete.hide()" type="button"/>
    </p:confirmDialog>
</h:form>
<p:dialog name="upload" id="mapping" header="Upload Mapping File" widgetVar="mappingFileDialog" fixedCenter="true">
    <h:form prependId="true" id="uploadMapping" enctype="multipart/form-data">
        <p:fileUpload fileUploadListener="#{panaceaController.handleMappingFileUpload}"
                      mode="advanced"
                      update="messages"
                      sizeLimit="1000000"
                      allowTypes="/(\.|\/)(xml)$/" oncomplete="mappingFileDialog.hide();"/>

    </h:form>
</p:dialog>
<p:dialog name="upload" id="publisherMapping" header="Upload Publishing File" widgetVar="publishingFileDialog"
          fixedCenter="true">
    <h:form prependId="true" id="uploadPublishing" enctype="multipart/form-data">
        <p:fileUpload fileUploadListener="#{panaceaController.handlePublishingFileUpload}"
                      mode="advanced"
                      update="messages"
                      sizeLimit="1000000"
                      allowTypes="/(\.|\/)(xml)$/" oncomplete="publishingFileDialog.hide();"/>

    </h:form>
</p:dialog>

<p:dialog name="upload" id="templateFile" header="Upload Templates" widgetVar="templatesFileDialog" fixedCenter="true">
    <h:form prependId="true" id="templateFileForm" enctype="multipart/form-data">
        <p:fileUpload fileUploadListener="#{panaceaController.handleTemplateFileUpload}"
                      mode="advanced"
                      update="messages main-panel"
                      multiple="true"
                      sizeLimit="1000000"
                      allowTypes="/(\.|\/)(ftl)$/" oncomplete="templatesFileDialog.hide();"/>

    </h:form>
</p:dialog>
</ui:define>
</ui:composition>
</html>
